// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   SET_INTImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.common.VersionInfo;
import com.sunwayhorizo.health.hl7.datatypes.ANY;
import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.CS;
import com.sunwayhorizo.health.hl7.datatypes.INT;
import com.sunwayhorizo.health.hl7.datatypes.IVL_INT;
import com.sunwayhorizo.health.hl7.datatypes.SET_INT;
import com.sunwayhorizo.health.hl7.datatypes.ST;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            SETCommonImpl, ANYImpl, BLImpl, CSImpl, 
//            INTImpl, STImpl, TYPEImpl

public class SET_INTImpl extends SETCommonImpl
    implements SET_INT
{

    public static final String RCS_ID = "$Header: SET_INTImpl.java 115.23 2005/09/16 09:22:53 amchanda noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: SET_INTImpl.java 115.23 2005/09/16 09:22:53 amchanda noship $", "oracle.apps.ctb.hl7.types.common");
    private static final SET_INT nullNI = new SET_INTImpl(CSImpl.valueOf("NI"));
    private static final SET_INT nullOTH = new SET_INTImpl(CSImpl.valueOf("OTH"));
    private static final SET_INT nullNINF = new SET_INTImpl(CSImpl.valueOf("NINF"));
    private static final SET_INT nullPINF = new SET_INTImpl(CSImpl.valueOf("PINF"));
    private static final SET_INT nullUNK = new SET_INTImpl(CSImpl.valueOf("UNK"));
    private static final SET_INT nullASKU = new SET_INTImpl(CSImpl.valueOf("ASKU"));
    private static final SET_INT nullNAV = new SET_INTImpl(CSImpl.valueOf("NAV"));
    private static final SET_INT nullMSK = new SET_INTImpl(CSImpl.valueOf("MSK"));
    private static final SET_INT nullNA = new SET_INTImpl(CSImpl.valueOf("NA"));
    private static final SET_INT nullNASK = new SET_INTImpl(CSImpl.valueOf("NASK"));

    public static SET_INT valueOf(INT aint[])
    {
        return new SET_INTImpl(aint);
    }

    public static SET_INT valueOf(long al[])
    {
        return new SET_INTImpl(al);
    }

    public static SET_INT valueOf(INT int1)
    {
        return new SET_INTImpl(int1);
    }

    public static SET_INT valueOf(Set set)
    {
        return new SET_INTImpl(set);
    }

    public static SET_INT nullSET_INT()
    {
        return new SET_INTImpl(((CS) (null)));
    }

    protected SET_INTImpl(INT aint[])
    {
        if(aint == null)
            throw ANYImpl.newNullException("SET<INT>", "constructor", "elements");
        for(int i = 0; i < aint.length; i++)
            if(aint[i] != null && aint[i].isNull().isFalse())
                mSet.add(aint[i]);

    }

    protected SET_INTImpl(long al[])
    {
        for(int i = 0; i < al.length; i++)
        {
            INT int1 = INTImpl.valueOf(al[i]);
            mSet.add(int1);
        }

    }

    protected SET_INTImpl(INT int1)
    {
        if(int1 == null || int1.isNull().isTrue())
        {
            throw ANYImpl.newNullException("SET<INT>", "constructor", "element");
        } else
        {
            mSet.add(int1);
            return;
        }
    }

    public SET_INTImpl(Set set)
    {
        super(set);
    }

    public SET_INTImpl(CS cs)
    {
        super(cs);
    }

    public BL contains(INT int1)
    {
        return BLImpl.valueOf(mSet.contains(int1));
    }

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.SET_INT;
    }

    public BL contains(SET_INT set_int)
    {
        if(isNull().isTrue())
            return BLImpl.FALSE;
        else
            return BLImpl.valueOf(mSet.containsAll(set_int.toSet()));
    }

    public SET_INT union(SET_INT set_int)
    {
        if(isNull().isTrue())
            if(set_int.isNull().isTrue())
                return this;
            else
                return set_int;
        if(set_int.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.addAll(set_int.toSet());
            return valueOf(hashset);
        }
    }

    public SET_INT union(INT int1)
    {
        if(int1.isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.add(int1);
            return new SET_INTImpl(hashset);
        }
    }

    public SET_INT except(INT int1)
    {
        if(isNull().isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            hashset.remove(int1);
            return new SET_INTImpl(hashset);
        }
    }

    public SET_INT except(SET_INT set_int)
    {
        if(isNull().or(set_int.isNull()).isTrue())
        {
            return this;
        } else
        {
            HashSet hashset = new HashSet(mSet);
            Set set = set_int.toSet();
            hashset.removeAll(set);
            return new SET_INTImpl(hashset);
        }
    }

    public SET_INT intersection(SET_INT set_int)
    {
        if(isNull().or(set_int.isNull()).isTrue())
            return nullSET_INT();
        HashSet hashset = new HashSet();
        for(Iterator iterator = set_int.toSet().iterator(); iterator.hasNext();)
        {
            INT int1 = (INT)iterator.next();
            if(mSet.contains(int1))
                hashset.add(int1);
        }

        return valueOf(hashset);
    }

    public SET_INT promotion(INT int1)
    {
        HashSet hashset = new HashSet();
        hashset.add(int1);
        return valueOf(hashset);
    }

    public BL equal(ANY any)
    {
        if(!(any instanceof SET_INT))
            return BLImpl.FALSE;
        if(isNull().or(any.isNull()).isTrue())
        {
            return BLImpl.FALSE;
        } else
        {
            SET_INT set_int = (SET_INT)any;
            return BLImpl.valueOf(equalsSet(set_int.toSet()));
        }
    }

    public IVL_INT hull()
    {
        throw ANYImpl.newUnsupportedException("SET<INT>", "hull");
    }

    public ST literal()
    {
        StringBuffer stringbuffer = new StringBuffer("{");
        for(Iterator iterator = mSet.iterator(); iterator.hasNext();)
        {
            INT int1 = (INT)iterator.next();
            stringbuffer.append(int1.literal().toString());
            if(iterator.hasNext())
                stringbuffer.append("; ");
        }

        stringbuffer.append("}");
        return STImpl.valueOf(stringbuffer.toString());
    }

    protected boolean verifyItem(Object obj)
    {
        return (obj instanceof INT) && ((INT)obj).nonNull().isTrue();
    }

    public int hashCode()
    {
        return super.hashCode();
    }

    public static SET_INT nullSET_INT(CS cs)
    {
        String s = null;
        if(cs == null || cs.literal().stringValue() == null || cs.isNull().isTrue())
            s = "NI";
        else
            s = cs.literal().stringValue();
        if(s.equals("NI"))
            return nullNI;
        if(s.equals("OTH"))
            return nullOTH;
        if(s.equals("NINF"))
            return nullNINF;
        if(s.equals("PINF"))
            return nullPINF;
        if(s.equals("UNK"))
            return nullUNK;
        if(s.equals("ASKU"))
            return nullASKU;
        if(s.equals("NAV"))
            return nullNAV;
        if(s.equals("MSK"))
            return nullMSK;
        if(s.equals("NA"))
            return nullNA;
        if(s.equals("NASK"))
            return nullNASK;
        else
            return nullNI;
    }

}
